package com.jeethink.erp.unit.controller;

import java.util.List;

import com.jeethink.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jeethink.common.annotation.Log;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.erp.unit.domain.TbProductUnit;
import com.jeethink.erp.unit.service.ITbProductUnitService;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.common.core.page.TableDataInfo;

/**
 * 商品计量单位Controller
 * 
 * @author ypr
 * @date 2021-05-31
 */
@RestController
@RequestMapping("/erp/unit")
public class TbProductUnitController extends BaseController
{
    @Autowired
    private ITbProductUnitService tbProductUnitService;

    /**
     * 查询商品计量单位列表
     */
    @PreAuthorize("@ss.hasPermi('erp:unit:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbProductUnit tbProductUnit)
    {
        startPage();
        List<TbProductUnit> list = tbProductUnitService.selectTbProductUnitList(tbProductUnit);
        return getDataTable(list);
    }

    /**
     * 导出商品计量单位列表
     */
    @PreAuthorize("@ss.hasPermi('erp:unit:export')")
    @Log(title = "商品计量单位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbProductUnit tbProductUnit)
    {
        List<TbProductUnit> list = tbProductUnitService.selectTbProductUnitList(tbProductUnit);
        ExcelUtil<TbProductUnit> util = new ExcelUtil<TbProductUnit>(TbProductUnit.class);
        return util.exportExcel(list, "unit");
    }

    /**
     * 获取商品计量单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:unit:query')")
    @GetMapping(value = "/{productUnitId}")
    public AjaxResult getInfo(@PathVariable("productUnitId") Long productUnitId)
    {
        return AjaxResult.success(tbProductUnitService.selectTbProductUnitById(productUnitId));
    }

    /**
     * 新增商品计量单位
     */
    @PreAuthorize("@ss.hasPermi('erp:unit:add')")
    @Log(title = "商品计量单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbProductUnit tbProductUnit)
    {
        return toAjax(tbProductUnitService.insertTbProductUnit(tbProductUnit));
    }

    /**
     * 修改商品计量单位
     */
    @PreAuthorize("@ss.hasPermi('erp:unit:edit')")
    @Log(title = "商品计量单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbProductUnit tbProductUnit)
    {
        return toAjax(tbProductUnitService.updateTbProductUnit(tbProductUnit));
    }

    /**
     * 删除商品计量单位
     */
    @PreAuthorize("@ss.hasPermi('erp:unit:remove')")
    @Log(title = "商品计量单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productUnitIds}")
    public AjaxResult remove(@PathVariable Long[] productUnitIds)
    {
        return toAjax(tbProductUnitService.deleteTbProductUnitByIds(productUnitIds));
    }

    @GetMapping("/unitList")
    public AjaxResult unitList(){
        List<TbProductUnit> unitList = tbProductUnitService.selectTbProductUnitList(new TbProductUnit());
        return AjaxResult.success(unitList);
    }

}
